import tornado.ioloop
import tornado.web
from common import jwt

class BaseHandler(tornado.web.RequestHandler):
    def get_jwt_token(self):
        """
        Retrieve the JWT token from the Authorization header.
        """
        authorization_header = self.request.headers.get('Authorization')
        if authorization_header and authorization_header.startswith('Bearer '):
            return authorization_header[7:]  # Remove 'Bearer ' prefix
        return None
    def get_current_user(self):
        token = self.get_jwt_token()
        if not token:
            return None,None
        try:
            status, payload = jwt.decode_jwt_token(token)  # Call the function from the imported module
            if status == 200:
                return payload['user_id'],payload['account_type']
        except tornado.web.HTTPError:
            return None,None
